﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;

using XGameFrame;
using XGameFrame.Graphic;

using XTowerDef.GameScreens;
using XGameFrame.Controls;
using XTowerDef.GameScreens.SettingScreenElements;

namespace XTowerDef.GameScreens
{
    public class SettingsScreen:BaseGameState
    {
        #region Event
        #endregion

        #region Fields
        Background backgroundImage;
        DisplayMouse displayMouse;
        MouseSprite mouseAnimation;
        DisplayMouselbl lblMouse;
        #endregion

        #region Constructor
        public SettingsScreen(Game game, GameStateManager manager)
            : base(game, manager)
        {
        }
        #endregion

        #region XNA Method Region

        public override void Initialize()
        {
            base.Initialize();
        }
        protected override void LoadContent()
        {
            // have to call first so that the ControlManager exists
            base.LoadContent();

            ContentManager Content = Game.Content;

            // the Picture for the Background
            backgroundImage = new Background(
                Content.Load<Texture2D>(@"Backgrounds\titlescreen"),
                GameRef.ScreenRectangle);
            // add the PictureBox to the ControlManager how will add the control to the 
            ControlManager.Add(backgroundImage);

            Texture2D checkbox_uncheck = Content.Load<Texture2D>(@"Controls\Checkbox\checkbox_no");
            Texture2D checkbox_check = Content.Load<Texture2D>(@"Controls\Checkbox\checkbox_yes");
            displayMouse = new DisplayMouse(checkbox_uncheck, checkbox_check, new Rectangle(195, 205, checkbox_check.Width, checkbox_check.Height));
            ControlManager.Add(displayMouse);
            displayMouse.onCheckedChangeEvent += new OnCheckedChange(OrginalMouseDisplay); 


            lblMouse = new DisplayMouselbl(new Vector2(220, 200), "Display Orginal Mouse");
            ControlManager.Add(lblMouse);
            if (OrginalMouse == false)
            {
                //new testing loading mouse
                Texture2D mouseGraphic = Content.Load<Texture2D>(@"GameGraphics\Mouse\glowing-cursor2");
                mouseAnimation = new MouseSprite(mouseGraphic, InputHandler.CurrentMousePosition);
                

                StaticSpriteManager.Add(mouseAnimation);
            }

        }

        // accept the sender as a control and place the arrow after the control position
        private void ControlManager_FocusChanged(object sender, EventArgs e)
        {
            Control control = sender as Control;
        }

        private void menuItem_Selected(object sender, EventArgs e)
        {
            
        }

        public override void Update(GameTime gameTime)
        {
            ControlManager.Update(gameTime, playerIndexInControl);
            AnimatedSpriteManager.Update(gameTime, playerIndexInControl);
            StaticSpriteManager.Update(gameTime, playerIndexInControl);
            base.Update(gameTime);
        }
        public override void Draw(GameTime gameTime)
        {
            GameRef.SpriteBatch.Begin();
            base.Draw(gameTime);
            ControlManager.Draw(GameRef.SpriteBatch);
            AnimatedSpriteManager.Draw(GameRef.SpriteBatch);
            StaticSpriteManager.Draw(GameRef.SpriteBatch);
            GameRef.SpriteBatch.End();
        }

        #endregion

        #region Methods

        void OrginalMouseDisplay(Boolean display)
        {
            GameRef.IsMouseVisible = display;
            if (display == true)
                StaticSpriteManager.Remove(mouseAnimation);
            else
                StaticSpriteManager.Add(mouseAnimation);
        }
        
        #endregion

    }
}
